{	Problem: http://codeforces.ru/problemset/problem/75/C
	 Verdict: Accepted
}
uses
        SysUtils, Math;

var
        x,y,i,q,cc,g,l,r,c,a,b,gg:longint;
        d:array[0..100010] of longint;

function check(x:longint):boolean;
begin
if (x>=a) and (x<=b) then begin
        result:=true;
        writeln(x);
end else result:=false;
end;

procedure swap(var a,b:longint);

var
        t:longint;

begin
t:=a;
a:=b;
b:=t;
end;

procedure sort(l,r:longint);

var
        i,j,x:longint;

begin
i:=l;
j:=r;
x:=d[(l+r) shr 1];
repeat
        while d[i]<x do inc(i);
        while d[j]>x do dec(j);
        if i<=j then begin
                swap(d[i],d[j]);
                inc(I);
                dec(j);
        end;
until i>j;
if l<j then sort(l,j);
if i<r then sort(i,r);
end;

function gcd(a,b:longint):longint;
begin
if a<b then swap(a,b);
while b>0 do begin
        a:=a mod b;
        swap(a,b);
end;
result:=a;
end;
         
begin
read(x,y);
g:=gcd(x,y);
cc:=0;
gg:=trunc(sqrt(g));
for i:=1 to gg do 
        if g mod i = 0 then begin
                inc(cc,2);
                d[cc-1]:=i;
                d[cc]:=g div i;
        end;
sort(1,cc);
read(q);
for i:=1 to q do begin
        read(a,b);
        l:=1;
        r:=cc;
        while r-l>1 do begin
                c:=(l+r) shr 1;
                if d[c]<b then l:=c else r:=c;
        end;
        if not check(d[l+1]) then
                if not check(d[l]) then
                        if not check(d[l-1]) then writeln(-1);
end;
end.